import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/modules/application/education/quiz/model.dart';
import 'package:enterprise_v6_app/app/modules/application/education/quiz/quiz_controller.dart';

const _dotUnfinish = Color(0x1A5C6DFF);
const _dotCorrect = Color(0xFF00CE78);
const _dotError = Color(0xFFFD6B6B);

class QuizWidgets {
  const QuizWidgets._();

  /// 显示 对/错/未答 指示器
  static Widget get statusIndicator {
    return Row(
      children: [
        _buildCardTopIndicator('正确', AppImages.icon_green_dot_fade),
        _buildCardTopIndicator('错误', AppImages.icon_red_dot_fade),
        _buildCardTopIndicator('未答', AppImages.icon_dot_fade),
      ],
    );
  }

  /// 题目顶部指示器
  static Widget _buildCardTopIndicator(String title, String icon) {
    return Row(
      children: [
        Image.asset(
          icon,
          height: 13.w,
          width: 13.w,
        ),
        AppGaps.hGap4,
        Text(
          title,
          style: TextStyle(fontSize: 12.w),
        ),
        AppGaps.hGap10,
      ],
    );
  }

  /// 显示题目序号
  static Widget topicDotIndicator(QuizTopic item, int idx) {
    Widget child;
    if (item.selectedIdx.isEmpty) {
      child = Container(
        decoration: BoxDecoration(
          color: _dotUnfinish,
          borderRadius: BorderRadius.circular(36.w),
        ),
        margin: EdgeInsets.all(9.w),
        padding: EdgeInsets.only(top: 7.7.w),
        child: Text(
          (idx + 1).toString(),
          textAlign: TextAlign.center,
          style: TextStyle(fontSize: 18.w, color: const Color(0xFFA5A9C8)),
        ),
      );
    } else if (item.isAnswerRight) {
      child = Container(
        decoration: BoxDecoration(
          color: _dotCorrect,
          borderRadius: BorderRadius.circular(36.w),
        ),
        margin: EdgeInsets.all(9.w),
        padding: EdgeInsets.only(top: 7.7.w),
        child: Text(
          (idx + 1).toString(),
          textAlign: TextAlign.center,
          style: TextStyle(fontSize: 18.w, color: Colors.white),
        ),
      );
    } else {
      child = Container(
        decoration: BoxDecoration(
          color: _dotError,
          borderRadius: BorderRadius.circular(36.w),
        ),
        margin: EdgeInsets.all(9.w),
        padding: EdgeInsets.only(top: 7.7.w),
        child: Text(
          (idx + 1).toString(),
          textAlign: TextAlign.center,
          style: TextStyle(fontSize: 18.w, color: Colors.white),
        ),
      );
    }
    return InkWell(
      onTap: () {
        final controller = Get.find<EducationQuizController>();
        controller.currentQuizIdx = idx;
        controller.update();
        Get.back();
      },
      child: child,
    );
  }

  /// 显示题目序号 （不需要点击）
  static Widget topicDotIndicatorNoClick(QuizTopic item, int idx) {
    Widget child;
    if (item.selectedIdx.isEmpty) {
      child = Container(
        decoration: BoxDecoration(
          color: _dotUnfinish,
          borderRadius: BorderRadius.circular(36.w),
        ),
        margin: EdgeInsets.all(9.w),
        padding: EdgeInsets.only(top: 7.7.w),
        child: Text(
          (idx + 1).toString(),
          textAlign: TextAlign.center,
          style: TextStyle(fontSize: 18.w, color: const Color(0xFFA5A9C8)),
        ),
      );
    } else if (item.isAnswerRight) {
      child = Container(
        decoration: BoxDecoration(
          color: _dotCorrect,
          borderRadius: BorderRadius.circular(36.w),
        ),
        margin: EdgeInsets.all(9.w),
        padding: EdgeInsets.only(top: 7.7.w),
        child: Text(
          (idx + 1).toString(),
          textAlign: TextAlign.center,
          style: TextStyle(fontSize: 18.w, color: Colors.white),
        ),
      );
    } else {
      child = Container(
        decoration: BoxDecoration(
          color: _dotError,
          borderRadius: BorderRadius.circular(36.w),
        ),
        margin: EdgeInsets.all(9.w),
        padding: EdgeInsets.only(top: 7.7.w),
        child: Text(
          (idx + 1).toString(),
          textAlign: TextAlign.center,
          style: TextStyle(fontSize: 18.w, color: Colors.white),
        ),
      );
    }
    return InkWell(
      onTap: () {
        // final controller = Get.find<EducationQuizController>();
        // controller.currentQuizIdx = idx;
        // controller.onlySwitchWrong = false;
        // controller.update();
        // Get.back();
      },
      child: child,
    );
  }
}
